package models

import (
	"github.com/go-xorm/xorm"
	_ "github.com/lib/pq"
)

var engine *xorm.Engine

func init() {
	//cs := "shd:612345@/shd"
	//cs := "user=shoptentest dbname=shoptentest sslmode=verify-full"
	//cs := "postgres://shopten:l9yus5nn@localhost/shopten?sslmode=disable"
	cs := "postgres://shopten:l9yus5nn@localhost/shopten?sslmode=disable"
	//cs := "postgres://shopten:c0m@zm7s1zs4r.pg.rds.aliyuncs.com:3433/shopten?sslmode=disable"
	var err error
	engine, err = xorm.NewEngine("postgres", cs)
	if err != nil {
		engine = nil
	}
}

func GetEngine() *xorm.Engine {
	if engine == nil {
		panic("db init fail")
	}

	return engine
}
